// pkgTask/pages/takephoto-task-list/index.js
const lbbTaskService = require('../service/task-service.js');
const lbbService = require('../../../pages/service/service.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordId:0,
    lbmId:0,
    hosBetTypeList:[],
    equCategoryId:0,
    equList:[],
    passCount:0,
    rejectCount:0,
    activeKey:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
       this.data.recordId = options.id
       this.data.lbmId = options.lbmId
       
       this.setData({
        taskStat: options.taskStat,
        lbmName: options.lbmName,
        startDate: options.startDate,
        endDate: options.endDate
       })
       console.log("view---->", options)
       this.getPutEquTypeList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
     this.getHosPhotoInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 跳转到设备拍摄页面
   */
  navToTakePhotoAudit(e) {
    console.log("toCheckPhoto==>", e)
    let data = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pkgTask/pages/task-takephoto-audit/index?id=' + data.id + '&equId=' + data.equid + '&lockType=' + data.locktype,
    })
  },

  getPutEquTypeList(){
    let that = this
    lbbService.getHosPutEquTypeList({
      lbmId:that.data.lbmId
    },
      function(res) {
         that.setData({
          hosBetTypeList: res.data,
         })
      })
  },

  changeEquType(e) {
    let that = this
    let equTypeIndex = e.detail
    let betTypeInfo = this.data.hosBetTypeList[equTypeIndex]
    console.log("changeEquType-->", equTypeIndex, betTypeInfo);
    this.data.equCategoryId = betTypeInfo.categoryId
    let selEquList = that.data.allEquMap[that.data.equCategoryId]
    let passCount = that.data.checkPassCount[that.data.equCategoryId]
    let rejectCount = that.data.checkRejectCount[that.data.equCategoryId]
    this.setData({
      equList: selEquList ? selEquList : [],
      passCount: passCount ? passCount : 0,
      rejectCount: rejectCount ? rejectCount : 0
    })
  },

  getHosPhotoInfo() {
    let that = this
 
    lbbTaskService.getPhotoEquList({
        hospitalRecordId: that.data.recordId,
        lbmId:that.data.lbmId
    }, function(res) {
        let equList = res.data
        if(!that.data.equCategoryId) {
           that.data.equCategoryId = res.categoryId
        }
        that.data.allEquMap = equList
        that.data.checkPassCount = res.checkPassCount
        that.data.checkRejectCount = res.checkRejectCount
        that.setData({
          equList: equList[that.data.equCategoryId],
          passCount: that.data.checkPassCount[that.data.equCategoryId],
          rejectCount: that.data.checkRejectCount[that.data.equCategoryId]
        })        
      })
  },
  
})